// models/userModel.js
const bcrypt = require('bcrypt');

class UserModel {
    constructor(db) {
        this.db = db;
    }

    async createUser(name, email, password) {
        const hashedPassword = await bcrypt.hash(password, 10);
        return new Promise((resolve, reject) => {
                this.db.query('INSERT INTO users (name, email, password) VALUES (?, ?, ?)', 
                            [name, email, hashedPassword], 
                            (err, results) => {
                    if (err) return reject(err);
                    resolve(results.insertId);
                });
        });
    }

    async getUserByEmail(email) {
        return new Promise((resolve, reject) => {
            this.db.query('SELECT * FROM users WHERE email = ?', [email], (err, results) => {
                if (err) return reject(err);
                resolve(results[0]);
            });
        });
    }
}

module.exports = UserModel;